package com.ruoyi.electronicFence.controller;


import com.ruoyi.common.config.DbInterfaceConfig;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.electronicFence.domain.A2StaticInfo;
import com.ruoyi.electronicFence.domain.DynamicsInfo;
import com.ruoyi.electronicFence.domain.dto.A2StaticInfoCondition;
import com.ruoyi.electronicFence.domain.vo.ReqVo;
import com.ruoyi.electronicFence.utils.HttpUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "AIS/ADS-B管理（免登录）")
@RestController
@RequestMapping("/webs/a2")
public class A2Controller extends BaseController
{
//    @Autowired
//    private IA2Service a2Service;
    
    @Autowired
    private DbInterfaceConfig dbInterfaceConfig;

    @ApiOperation("获取2A静态信息列表（分页）")
    @GetMapping("/a2StaticInfoList")
    public TableDataInfo a2StaticInfoList(@Validated @ModelAttribute final A2StaticInfoCondition condition)
    {
        StringBuilder sb = new StringBuilder("");
        sb.append("select id  ,  glid  ,  mbbm  ,  mblx  ,  mbmc  " +
                "from   J_KY_R_FJJCJTB   ORDER BY id DESC ");
        List<A2StaticInfo> staticInfos = (List<A2StaticInfo>) HttpUtil.getListBean(dbInterfaceConfig, new ReqVo(sb.toString()), A2StaticInfo.class);
        staticInfos.forEach(sta -> {
            StringBuilder sb1 = new StringBuilder("SELECT id,jd,wd" +
                    " FROM J_KY_S_AISADSBDWXX WHERE MBBM = '").append(sta.getMbbm()) .append("' ORDER BY JJSJ DESC");
            List<DynamicsInfo> listBean = (List<DynamicsInfo>) HttpUtil.getListBean(dbInterfaceConfig, new ReqVo(sb1.toString()), DynamicsInfo.class);
            if (listBean != null && listBean.size() > 0){
                sta.setLon(listBean.get(0).getJd() / 1000000.0);
                sta.setLat(listBean.get(0).getWd() / 1000000.0);
            }
        });

        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setRows(staticInfos);
        tableDataInfo.setCode(HttpStatus.SUCCESS);
        tableDataInfo.setMsg("查询成功");
//        tableDataInfo.setTotal(page.getTotal());
        return tableDataInfo;
    }

}
